package com.jcode.netty.serialize;

import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Date;

import org.apache.commons.lang3.SerializationUtils;

import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import com.jcode.netty.exception.SerializationException;

/**
 * Java序列化
 *
 * @Author dreajay
 * @DateTime 2017年4月16日 下午12:05:49
 *
 */
public class JavaSerializer implements Serializer {
	private static SerializeConfig config = new SerializeConfig();
	public static final Charset CHARSET = Charset.forName("UTF-8");

	static {
		config.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
	}

	@Override
	public SerializeType getType() {
		return SerializeType.JAVA;
	}

	@Override
	public byte[] serialize(Serializable obj) throws SerializationException {
		return SerializationUtils.serialize(obj);
	}

	@Override
	public <T> T deserialize(byte[] data, Class<T> clazz) throws SerializationException {
		return SerializationUtils.deserialize(data);
	}

}
